﻿$(function () {
    $("#aGoodOrderSubmit").click(function () {

        $("#aGoodOrderSubmit").attr('disabled', "true");
        var memname = $.trim($("#info_name").val());
        var telnumber = $.trim($("#info_phone").val());
        var address = $.trim($("#info_address").val());

        if (memname == "") { alert("请输入您的姓名!"); return; }
        if (telnumber == "") { alert("请输入您的手机号码!"); return; } else { if (!telnumber.IsMobile()) { alert("您输入的手机号码格式有误"); return; } }
        if (address == "") { alert("请输入您的收货地址!"); return; }
        ui.prompt('请输入您的密码', function (z) {
            if (z) {
                var pwd = z;

                if (!pwd)//如果返回的有内容  
                {
                    return;
                }
                $.get("../../Service/AjaxService.ashx?Method=GoodApplicationNew",
            {
                "MemID": getCookie("uid"),
                "MemName": memname,
                "ExchangeTelePhone": telnumber,
                "ExchangeAddress": address,
                "MicroOrderDiscountMoney": $("#zhifu_price2").html(),
                "MicroOrderPoint": $("#zhifu_price2").html(),
                "pwd": pwd
            }
            , function (text) {
                if (text == "0") { alert("系统有点繁忙，提交失败！"); } else if (text == "-3") {
                    alert("密码错误");
                } else {


                    $.get("../../Service/AjaxService.ashx?Method=GoodPay",
                          {
                              "MicroOrderID": text,
                              "MemID": getCookie("uid"),
                              "payMoney": $("#zhifu_price2").html()
                          }
                          , function (text) {
                              switch (text) {
                                  case "0":
                                      alert("系统有点繁忙，提交失败!");
                                      break;
                                  case "-1":
                                      alert("您当前金额不足!");
                                      break;
                                  case "-2":
                                      alert("该订单已支付，请勿重新提交!");
                                      break;
                                  case "-4":
                                      alert("消费金额限制，不允许消费!");
                                      break;
                                  default:
                                      alert("支付成功!");
                                      //清空localStorage对象
                                      var strKey = "";
                                      var getData = "";
                                      for (var i = localStorage.length - 1; i >= 0; i--) {
                                          strKey = localStorage.key(i);
                                          if (strKey.substring(0, 5) == "good_") {
                                              getData = JSON.parse(xxl.xd.getValue(strKey));
                                              localStorage.removeItem(getData.Type);
                                          }
                                      }
                                      //清空Cookie
                                      setCookie("goodlist", "");
                                      setCookie("goodlist_num", "0");
                                      setCookie("goodlist_price", "0");
                                      $("#aGoodOrderSubmit2").click();
                                      window.location.href = "GoodsList.aspx";
                                      break;
                              }

                          }, "text")





                }
                $("#aGoodOrderSubmit").removeAttr("disabled");
            }, "text")
            } else {
                return;
            }
        });



    })
})